﻿@model ADZ_JingjiaConfig
@{
    ViewBag.Title = "竞价配置编辑";
    Layout = "~/Views/Shared/_ContentLayout.cshtml";

    var viewModel = Model ?? new ADZ_JingjiaConfig();
    ADZ_MasterEntities dbcontext = new ADZ_MasterEntities();
    Dictionary<string, string> dc = new Dictionary<string, string>();
}

<form id="S_Form" action="@Url.Action("addconfig", "jingjia")" method="post" class="definewidth m20" enctype="multipart/form-data">
    <table class="table table-bordered table-hover definewidth m10">
        <tr>
            <td colspan="4" style="width:50%">
                <h5>
                    @ViewBag.Title @(viewModel.jingjia_config_id > 0 ? "竞价配置编号：" + viewModel.jingjia_config_id : "")
                    @if (viewModel.baoming_counts > 0)
                    {
                        <info>当前报名人数 @viewModel.baoming_counts 人</info>
                    }
                </h5>
                <input type="hidden" value="@viewModel.jingjia_config_id" name="jingjia_config_id" id="jingjia_config_id" />
            </td>
        </tr>
        <tr>
            <td width="6%" class="tableleft">竞价配置名称<em>*</em></td>
            <td width="44%">
                <input type="text" name="jingjia_config_name" style="width:300px;" value="@Model.jingjia_config_name" />
            </td>
            <td width="6%" class="tableleft">竞价状态<em>*</em></td>
            <td>
                <input type="radio" name="jingjia_config_satus" style="vertical-align:middle; margin-bottom:6px;" value="@((int)JingjiaConfigStatus.Default)" />未开始
                <input type="radio" name="jingjia_config_satus" style="vertical-align:middle; margin-bottom:6px;" value="@((int)JingjiaConfigStatus.InProgress)" />进行中
                <input type="radio" name="jingjia_config_satus" style="vertical-align:middle; margin-bottom:6px;" value="@((int)JingjiaConfigStatus.Finished)" />已结束
            </td>
        </tr>
        <tr>
            <td>
                保证金额<em>*</em>
            </td>
            <td>
                <input type="text" name="baozheng_price" style="width:300px;" value="@Model.baozheng_price" />
            </td>
            <td class="tableleft">开始时间<em>*</em></td>

            <td>
                <input type="text" name="begin_time" style="width:160px;" class="calendar calendar-time" maxlength="50" value="@Model.begin_time.ToString(1)" />
            </td>
        </tr>
        <tr>
            <td class="tableleft">内容描述</td>
            <td><textarea name="remark" style="width:80%;" maxlength="550" cols="4">@Model.remark</textarea></td>
            <td class="tableleft">结束时间<em>*</em></td>
            <td>
                <input type="text" name="end_time" style="width:160px;" class="calendar calendar-time" maxlength="50" value="@Model.end_time.ToString(1)" />
            </td>

        </tr>
        <tr></tr>

        <tr>
            <td class="tableleft"></td>
            <td colspan="3">
                <p><span id="spMsg"></span></p>
                <button type="submit" class="btn btn-primary">保存</button> &nbsp;&nbsp;

                <button type="button" backpageid="jingjia/getconfiglist" class="btn btn-success" name="backid" id="backid">返回列表</button>
            </td>
        </tr>
    </table>
    @if (viewModel.jingjia_config_id > 0)
    {
        <h5>竞价包列表  <a href="/jingjia/editconfigpackage?jingjia_config_id=@viewModel.jingjia_config_id">编辑竞价包信息</a></h5>
        <table class="table table-bordered table-hover definewidth m10">
            <thead>
                <tr>
                    <th>编号</th>
                    <th style="text-align:center;vertical-align:middle;">竞价图片</th>
                    <th>竞价包名称</th>
                    <th>竞价状态</th>
                    <th>是否含税</th>
                    <th>起拍价</th>
                    <th>加价幅度</th>
                    <th>留置价</th>
                    <th>延时周期</th>
                    <th>拍卖类型</th>
                    <th>结束时间</th>
                    <th>出价次数</th>
                    <th>围观次数</th>
                    <th>最后出价时间</th>
                    <th>最后出价金额</th>
                    <th>操作</th>
                </tr>
            </thead>
            @{
                var jingjia_packages =
                 from t in dbcontext.ADZ_JingjiaMaster
                 where t.jingjia_config_id.Equals(viewModel.jingjia_config_id)
                 select t;

                int index = 0;
                foreach (var m in jingjia_packages)
                {
                    index++;
                    <tr class="@HtmlPagerHelper.TrClass(index)">
                        <td>@m.jingjia_id</td>
                        <td style="text-align:center;vertical-align:middle;">
                            <img src="@ImageFileBiz.GetImg(m.img_url,"small")" class="height30" />
                        </td>
                        <td>@m.jingjia_name</td>
                        <td>
                            @if (m.jingjia_satus == 0)
                            {
                                <info>未开始</info>
                            }
                            else if (m.jingjia_satus == 1)
                            {
                                <info class="orange">竞价中</info>
                            }
                            else if (m.jingjia_satus == 2)
                            {
                                if (m.jingjia_deal_status == 2)
                                {
                                    <info class="green">已成交</info>
                                    var jingjiaSubmit = dbcontext.ADZ_JingjiaSubmit.FirstOrDefault(t => t.jingjia_id == m.jingjia_id && t.is_hit == 1);
                                    if (jingjiaSubmit != null)
                                    {
                                        if (jingjiaSubmit.status == 2)
                                        {
                                            <info class="red">未付款 <a href="/OrderMaster/OrderMasterInfo/@jingjiaSubmit.order_master_id">查看订单</a></info>
                                        }
                                        if (jingjiaSubmit.status == 10)
                                        {
                                            <info class="green">已付款 <a href="/OrderMaster/OrderMasterInfo/@jingjiaSubmit.order_master_id">查看订单</a></info>
                                        }
                                    }
                                }
                                else
                                {
                                    <info class="red">已流拍</info>
                                }
                            }
                        </td>
                        <td>
                            @if (m.include_tax == 1)
                            {
                                <info class="green">含税</info>
                            }
                            else
                            {
                                <info class="">未含税</info>
                            }
                        </td>
                        <td>@m.base_price.ToString("N2")</td>
                        <td>
                            @m.step_price.ToString("N2")
                            @if (m.step_price_max > 0)
                            {
                                <info> - @m.step_price_max.ToString("N2")</info>
                            }
                        </td>
                        <td>
                            @if (@m.liuzhi_price > 0)
                            {
                                <info>@m.liuzhi_price.ToString("N2")</info>
                            }
                        </td>
                        <td>@m.stay_miniutes 分钟/次</td>
                        <td>@m.jingjia_type</td>
                        <td>@m.real_end_time.ToString(1)</td>
                        <td>
                            <a href="/jingjia/ChujiaGetList?jingjia_id=@m.jingjia_id">@m.chujia_counts</a>
                        </td>
                        <td>@m.weiguan_counts</td>
                        <td>@m.last_time.ToString(1)</td>
                        <td>@m.last_price.ToString("N2")</td>
                        <td>
                            <a href="@Url.Action("add", "jingjia", new { id = m.jingjia_id})">编辑</a>
                            <a href="javascript:void(0);" onclick="toDel(@m.jingjia_id)">删除</a>
                        </td>
                    </tr>
                }
            }
        </table>
    }



    <script>
        BUI.use('bui/overlay', function (overlay) {
            $(function () {
                switch ('@Model.jingjia_config_satus') {
                    case '0':
                        $("input[name='jingjia_config_satus']").get(0).checked = true;
                        break;
                    case '1':
                        $("input[name='jingjia_config_satus']").get(1).checked = true;
                        break;
                    case '2':
                        $("input[name='jingjia_config_satus']").get(2).checked = true;
                        break;
                }

                var validator = $('form').validate({
                    errorLabelContainer: $("#errorContainer"),
                    errorElement: "span",
                    rules: {
                        img_url: { required: true },
                        huodong_status: { required: true },
                        begin_time: { required: true },
                        huodong_title: { required: true }
                    },
                    submitHandler: function (form) {
                        $(form).ajaxSubmit(function (result) {
                            ShowActionResult(result, function () { self.location = document.referrer; });
                        });
                    }
                });

            });
        });
    </script>
</form>
